package apigateway.project.core;

import apigateway.project.core.netty.NettyHttpClient;
import apigateway.project.core.netty.NettyHttpServer;
import apigateway.project.core.netty.processor.NettyCoreProcessor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Container implements LifeCycle{
    private final Config config;
    private NettyCoreProcessor processor;
    private NettyHttpServer httpServer;
    private NettyHttpClient httpClient;
    //通过构造函数获得配置信息并初始化
    public Container(Config config) {
        this.config = config;
        init();
    }
    @Override
    public void init() {
        NettyCoreProcessor processor = new NettyCoreProcessor();
        this.processor = processor;
        this.httpServer = new NettyHttpServer(config, processor);
        //TODO this.httpClient
        this.httpClient = new NettyHttpClient(config,httpServer.getEventLoopWork());
    }

    @Override
    public void start() {
        processor.start();
        httpServer.start();
        httpClient.start();
        log.info("container started");
    }

    @Override
    public void shutdown() {
        processor.shutDown();
        httpServer.shutdown();
        httpClient.shutdown();
    }
}
